﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace DarrenSoft.Presentation.WebForm.ajaxHandler.Department
{
    using DarrenSoft.Core;
    using DarrenSoft.Domain.Extends;
    using DarrenSoft.Domain.Entities;
    using DarrenSoft.Facade;
    public partial class List : System.Web.UI.Page
    {      
        private string _operType = string.Empty;
        private string _response = string.Empty;
        public IDepartmentFacade DepartmentFacade = new DepartmentFacade();
        protected void Page_Load(object sender, EventArgs e)
        {
            this._operType = PageRequest.GetQueryString("oper");
            switch (this._operType)
            {
                case "List":
                    ListDepartment();
                    break;
                default:
                    DefaultResponse();
                    break;
            }
            Response.Write(this._response);
        }
        private void ListDepartment()
        {
            var pageIndex = PageRequest.GetQueryInt("pageIndex");
            var pageSize = PageRequest.GetQueryInt("pageSize");
            var recordCount = 0;
            IList<Department> departmentList = DepartmentFacade.Find(out recordCount,string.Empty, new PagerBase() { PageIndex = pageIndex, PageSize = pageSize});
            this._response = JsonHelper.JsonGridFormat<Department>(pageIndex,pageSize,recordCount, departmentList,null);
      
        }
        /// <summary>
        /// 默认返回
        /// </summary>
        private void DefaultResponse()
        {
            this._response =JsonHelper.JsonFormat(JsonResult(false, "请求失败!"));
        }
        /// <summary>
        /// 输出json结果
        /// </summary>
        /// <param name="success">是否操作成功,false表示失败;true表示成功</param>
        /// <param name="str">输出字符串</param>
        /// <returns></returns>
        protected JsonDefaultResult JsonResult(bool success, string str)
        {
            return new JsonDefaultResult() { Result = success, Message = str };
        }
        }
    
}
